package rsj.service.organization;

import com.alibaba.fastjson.JSON;
import com.rlyy.aibase.utils.base.MapNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import rsj.api.account.entity.Organization;
import rsj.api.organization.entity.UpdateIp;
import rsj.db.dbutils.UniqueID;
import rsj.sql.org.OrganizationDao;

import java.time.LocalDateTime;

/**
 * 机构
 *
 * @author yuanqinglong
 * @since 2021/7/16 14:37
 */
@Service
public class OrganizationServiceImpl implements IOrganizationService {

    @Autowired
    private OrganizationDao organizationDao;


    /**
     * 添加组织
     *
     * @param organization 组织
     */
    @Override
    public Organization addOrganization(Organization organization) {
        organization.setOrgId(String.valueOf(UniqueID.generateId()));
        organization.setOrgUtime(LocalDateTime.now());
        organizationDao.addOrganization(organization);
        return organization;
    }

    /**
     * 得到组织
     *
     * @param orgId org id
     * @return {@link Organization}
     */
    @Override
    public Organization getOrganization(String orgId) {
        MapNode organization = organizationDao.getOrganization(orgId);
        return JSON.parseObject(JSON.toJSONString(organization.toMap()), Organization.class);
    }

    /**
     * 更新组织
     *
     * @param organization 组织
     */
    @Override
    public void updateOrganization(Organization organization) {

    }

    /**
     * 更新的ip地址
     *
     * @param updateIp 更新的ip
     */
    @Override
    public void updateIpAddress(UpdateIp updateIp) {
        organizationDao.updateIpAddress(updateIp);
    }
}
